#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>

int gval = 100;

int main()
{
    pid_t id = fork();
    if(id<0)
    {
        perror("fork");
        return -1;
    }
    else if(id == 0)
    {
        //child
        while(1)
        {
            gval += 100;
            printf("我是子进程,gval = %d\n",gval);
            sleep(1);
        }
    }
    else
    {
        //parent
        while(1)
        {
            printf("我是父进程,gval = %d\n",gval);
            sleep(1);
        }

    }
    return 0;
}

int main2()
{
    printf("我是父进程,我的pid:%d\n",getpid());
    fork();
    printf("进程开始,我的pid:%d\n",getpid());
	return 0;
}

int main1()
{
    printf("我是一个进程,我的pid:%d\n",getpid());
    pid_t id = fork();

    if(id < 0)
    {
        perror("fork");
        return -1;
    }
    else if(id == 0)
    {
        //child
        printf("我是子进程,我的pid:%d,我的ppid:%d\n",getpid(),getppid());
        sleep(1);
    }
    else
    {
        //parent
        printf("我是父进程，我的pid:%d\n",getpid());
        sleep(1);
    }

    return 0;
}
